package com.sdp.flow.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sdp.core.bizc.db.Query;
import com.sdp.core.bizc.threadLocal.ContextManager;
import com.sdp.core.bizc.utils.CoreConstantsEnum;
import com.sdp.core.bizc.vo.DataCenter;
import com.sdp.core.bizc.vo.Result;
import com.sdp.flow.db.service.IActRuTaskService;
import com.sdp.flow.dto.TodoTaskView;

@RestController
@RequestMapping("/todoTask")
public class TodoTaskController {

	@Autowired
	private IActRuTaskService ruTaskService;
	
	@Autowired
	private Query query;
	
	@PostMapping(value="/list")
	public Result<?> list(@RequestBody DataCenter dataCenter) {
		String systemNo = ContextManager.getContextData(CoreConstantsEnum.header中的模块参数名.getCode());
//		String accountNo = ContextManager.getContextData(CoreConstantsEnum.token中账号的属性名.getCode());
		String empNo = ContextManager.getContextData(CoreConstantsEnum.token中工号的属性名.getCode());
		QueryWrapper<TodoTaskView> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("a.ASSIGNEE_", empNo)
			.or(qw -> qw.isNull("a.ASSIGNEE_").eq("b.USER_ID_", empNo))
			.eq("c.SYSTEM_NO", systemNo);
		IPage<TodoTaskView> pageList = query.viewPage(ruTaskService, TodoTaskView.class, dataCenter, queryWrapper);
		return Result.ok(pageList); 
	}
}
